<template>
  <div class="div">
    <div>
      <van-nav-bar
        color="#333"
        title="收货地址"
        left-arrow
        @click-left="onClickLeft"
      />
  <van-address-list
    v-model="chosenAddressId"
    :list="list"
    default-tag-text="默认"
    @add="onAdd"
    @edit="onEdit"
  />
  </div>
  </div>
</template>
<script>
import { Toast } from "vant";
import { addressList } from '../../assets/api/addrapi.js'
export default {
  data() {
    return {
      list: [],
      chosenAddressId: 1,
    };
  },
  created(){
    this.getMyadd()
  },
  methods: {
    onClickLeft() {
      this.$router.push('/my')
    },
    onAdd() {
      this.$router.push("/add");
    },
    onEdit(item, index) {
      Toast("编辑地址:" + index);
    },
    getMyadd(){
      addressList().then(r=>{
        console.log(r.data.data.list)
        this.list = r.data.data.list
        for(let x in r.data.data.list){
          this.list[x].address = r.data.data.list[x].province + r.data.data.list[x].city + r.data.data.list[x].county
        }
      })
    }
  },
};
</script>